#define _GNU_SOURCE
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

void *red_thread(void *arg)
{
    char code = *(char *)arg;
    printf("红玫瑰开启了她的旅程\n");

    char buff[100];
    while (1)
    {
        fgets(buff, sizeof(buff), stdin); // 读取键盘输入
        if (buff[0] == code)
        {
            printf("红玫瑰结束了她的旅程\n");
            return "上海";
        }
        else
        {
            printf("红玫瑰告诉你她的秘密%s\n", buff);
        }
    }
}

void *white_thread(void *arg)
{
    char code = *(char *)arg;
    printf("白玫瑰开启了她的旅程\n");

    char buff[100];
    while (1)
    {
        fgets(buff, sizeof(buff), stdin); // 读取键盘输入
        if (buff[0] == code)
        {
            printf("白玫瑰结束了她的旅程\n");
            return "北京";
        }
        else
        {
            printf("白玫瑰告诉你她的秘密%s\n", buff);
        }
    }
}
int main(int argc, char const *argv[])
{
    pthread_t red_pt, white_pt;
    char red = 'r';
    char white = 'w';
    pthread_create(&red_pt, NULL, red_thread, &red);
    pthread_create(&white_pt, NULL, white_thread, &white);

    char *red_jj;
    char *white_jj;
    pthread_join(red_pt, (void **)&red_jj);
    pthread_join(white_pt, (void **)&white_jj);

    printf("红玫瑰的结局她去了%s\n", red_jj);
    printf("白玫瑰的结局她去了%s\n", white_jj);
    return 0;
}
